﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TV4Home.WebInterface.UI.Code;

namespace TV4Home.WebInterface.UI.Controls
{
    public partial class NavigationControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (Control ctrl in this.Navigation.Controls)
            {
                if (ctrl is NavigationButtonBase)
                {
                    NavigationButtonBase navCtrl = (NavigationButtonBase)ctrl;

                    if (IsSameUrlAsCurrentUrl(navCtrl.TargetURL))
                        navCtrl.IsPressed = true;
                }
            }
        }

        /// <summary>
        /// Determines whether the given Url is the same as the Url of the current document.
        /// </summary>
        /// <param name="url">The Url that should be checked.</param>
        /// <returns><c>True</c> if the given Url is the same as the Url of the current document; otherwise, <c>false</c>.</returns>
        private bool IsSameUrlAsCurrentUrl(string url)
        {
            return url.ToLower() == this.Request.AppRelativeCurrentExecutionFilePath.ToLower();
        }
    }
}